ShortcutKey2URL: 2URL4DLT
from ShortcutKey2URL自分用
ShortcutKey2URL: 2URL4DLT
code: script.js
/* いつもお世話になっているクリップボードコピースニペット */
window.COPY_TO_CLIPBOARD = window.COPY_TO_CLIPBOARD ?? {};
window.COPY_TO_CLIPBOARD.exec = text => retryCount => {
const textarea = document.createElement('textarea');
textarea.textContent = text;
const body = document.querySelector('body');
body.appendChild(textarea);
textarea.select();
const copied = new Array(1 + retryCount).fill().reduce((prev, curr, i) => {
const count = i + 1;
if (prev) return true;
console.log(Try copying: ${count} time${i?'s':''});
/* 'copy'が機能しないページがあるため'cut'に変更 */
return document.execCommand('cut');
}, false);
body.removeChild(textarea);
return copied;
};
/* タイトル */
window.URL_INFO = window.URL_INFO ?? {};
window.URL_INFO.get = () => {
const replacers = {
/* ":": "\uff1a", */
"\\[": "\uff3b",
"\\]": "\uff3d"
};
const allReplace = title => replacers =>
Object.entries(replacers).reduce((replacedTitle, matcher, replacer) =>
replacedTitle.replace(new RegExp(matcher, "g"), replacer), title);
return "+ allReplace(document.title)(replacers) + " " + document.URL + "";
};
window.COPY_TO_CLIPBOARD.exec(window.URL_INFO.get())(0);